<template>
	<view class="profile-container">
		<!-- 用户信息卡片 -->
		<view class="user-card">
			<view class="user-avatar">
				<image :src="userInfo.avatar" mode="aspectFill" @tap="chooseAvatar"></image>
			</view>
			<view class="user-info">
				<text class="username">{{ userInfo.nickname }}</text>
				<text class="user-id">ID: {{ userInfo.id }}</text>
				<text class="join-date">加入时间: {{ userInfo.joinDate }}</text>
			</view>
			<view class="edit-btn" @tap="editProfile">
				<text>编辑</text>
			</view>
		</view>

		<!-- 智商评估卡片 -->
		<view class="iq-card">
			<view class="iq-header">
				<text class="iq-title">综合智商评估</text>
				<text class="iq-score">{{ overallIQ }}</text>
			</view>
			<view class="iq-level">
				<text class="level-text">{{ iqLevel }}</text>
				<view class="level-bar">
					<view class="level-progress" :style="{width: iqProgress + '%'}"></view>
				</view>
			</view>
		</view>

		<!-- 测试统计 -->
		<view class="stats-section">
			<view class="section-title">
				<text>测试统计</text>
			</view>
			<view class="stats-grid">
				<view class="stat-item" v-for="(stat, index) in testStats" :key="index">
					<view class="stat-icon">
						<text class="iconfont">{{ stat.icon }}</text>
					</view>
					<view class="stat-info">
						<text class="stat-name">{{ stat.name }}</text>
						<text class="stat-count">{{ stat.count }}次</text>
						<text class="stat-best">最佳: {{ stat.best }}</text>
					</view>
				</view>
			</view>
		</view>

		<!-- 成绩详情 -->
		<view class="scores-section">
			<view class="section-header">
				<text class="section-title">我的成绩</text>
				<text class="view-all" @tap="viewScoreAnalysis">详细分析</text>
			</view>
			
			<!-- 成绩概览 -->
			<view class="score-overview">
				<view class="overview-item" v-for="(item, index) in scoreOverview" :key="index">
					<view class="overview-icon">{{ item.icon }}</view>
					<view class="overview-info">
						<text class="overview-label">{{ item.label }}</text>
						<text class="overview-value">{{ item.value }}</text>
					</view>
					<view class="overview-trend" :class="item.trend">
						<text>{{ item.trendText }}</text>
					</view>
				</view>
			</view>
			
			<!-- 各项测试最佳成绩 -->
			<view class="best-scores">
				<view class="best-score-item" v-for="(score, index) in bestScores" :key="index">
					<view class="score-header">
						<view class="score-icon">{{ score.icon }}</view>
						<view class="score-name">{{ score.name }}</view>
						<view class="score-value">{{ score.value }}</view>
					</view>
					<view class="score-progress">
						<view class="progress-bar">
							<view class="progress-fill" :style="{width: score.progress + '%'}"></view>
						</view>
						<text class="progress-text">{{ score.level }}</text>
					</view>
				</view>
			</view>
		</view>

		<!-- 最近测试记录 -->
		<view class="recent-section">
			<view class="section-header">
				<text class="section-title">最近测试</text>
				<text class="view-all" @tap="viewAllRecords">查看全部</text>
			</view>
			<view class="record-list">
				<view class="record-item" v-for="(record, index) in recentRecords" :key="index" @tap="viewRecord(record)">
					<view class="record-icon">
						<text class="iconfont">{{ record.icon }}</text>
					</view>
					<view class="record-info">
						<text class="record-name">{{ record.testName }}</text>
						<text class="record-date">{{ record.date }}</text>
					</view>
					<view class="record-score">
						<text class="score-value">{{ record.score }}</text>
						<text class="score-unit">{{ record.unit }}</text>
					</view>
				</view>
			</view>
		</view>

		<!-- 成就徽章 -->
		<view class="achievement-section">
			<view class="section-title">
				<text>成就徽章</text>
				<text class="achievement-count">{{ unlockedCount }}/{{ achievements.length }}</text>
			</view>
			
			<!-- 成就统计 -->
			<view class="achievement-stats">
				<view class="stat-item">
					<text class="stat-label">已解锁</text>
					<text class="stat-value">{{ unlockedCount }}</text>
				</view>
				<view class="stat-item">
					<text class="stat-label">传奇</text>
					<text class="stat-value legendary">{{ legendaryCount }}</text>
				</view>
				<view class="stat-item">
					<text class="stat-label">史诗</text>
					<text class="stat-value epic">{{ epicCount }}</text>
				</view>
				<view class="stat-item">
					<text class="stat-label">稀有</text>
					<text class="stat-value rare">{{ rareCount }}</text>
				</view>
			</view>
			
			<view class="badge-grid">
				<view class="badge-item" 
					v-for="(badge, index) in achievements" 
					:key="badge.id" 
					:class="[badge.rarity, {unlocked: badge.unlocked, 'has-progress': badge.progress > 0 && !badge.unlocked}]"
					@tap="showBadgeDetail(badge)">
					
					<view class="badge-icon">
						<text class="iconfont">{{ badge.icon }}</text>
						<view v-if="badge.unlocked" class="unlock-effect"></view>
					</view>
					
					<text class="badge-name">{{ badge.name }}</text>
					
					<!-- 进度条 -->
					<view v-if="!badge.unlocked && badge.progress > 0" class="badge-progress">
						<view class="progress-bar">
							<view class="progress-fill" :style="{width: (badge.progress / badge.maxProgress * 100) + '%'}"></view>
						</view>
						<text class="progress-text">{{ badge.progress }}/{{ badge.maxProgress }}</text>
					</view>
					
					<!-- 稀有度标识 -->
					<view class="rarity-badge" :class="badge.rarity">
						<text>{{ getRarityText(badge.rarity) }}</text>
					</view>
				</view>
			</view>
		</view>
		
		<!-- 成就详情弹窗 -->
		<view v-if="showAchievementDetail" class="achievement-modal" @tap="closeAchievementDetail">
			<view class="modal-content" @tap.stop>
				<view class="modal-header">
					<view class="achievement-icon" :class="[selectedAchievement?.rarity, {unlocked: selectedAchievement?.unlocked}]">
						<text>{{ selectedAchievement?.icon }}</text>
					</view>
					<view class="achievement-info">
						<text class="achievement-title">{{ selectedAchievement?.name }}</text>
						<text class="achievement-rarity" :class="selectedAchievement?.rarity">{{ getRarityText(selectedAchievement?.rarity) }}</text>
					</view>
					<view class="close-btn" @tap="closeAchievementDetail">
						<text>×</text>
					</view>
				</view>
				
				<view class="modal-body">
					<text class="achievement-description">{{ selectedAchievement?.description }}</text>
					<text class="achievement-condition">解锁条件：{{ selectedAchievement?.condition }}</text>
					
					<view v-if="!selectedAchievement?.unlocked" class="progress-section">
						<view class="progress-header">
							<text class="progress-label">完成进度</text>
							<text class="progress-value">{{ selectedAchievement?.progress }}/{{ selectedAchievement?.maxProgress }}</text>
						</view>
						<view class="progress-bar-large">
							<view class="progress-fill" :style="{width: (selectedAchievement?.progress / selectedAchievement?.maxProgress * 100) + '%'}"></view>
						</view>
						<text class="progress-percent">{{ Math.round(selectedAchievement?.progress / selectedAchievement?.maxProgress * 100) }}%</text>
					</view>
					
					<view v-if="selectedAchievement?.unlocked" class="unlock-info">
						<text class="unlock-status">🎉 已解锁</text>
						<text class="unlock-date">解锁时间：{{ formatDate(selectedAchievement?.unlockDate) }}</text>
					</view>
				</view>
			</view>
		</view>

		<!-- 设置选项 -->
		<view class="settings-section">
			<view class="section-title">
				<text>设置</text>
			</view>
			<view class="setting-list">
				<view class="setting-item" @tap="showFeedbackModal">
					<text class="setting-name">意见反馈</text>
					<text class="iconfont setting-arrow">></text>
				</view>
				<view class="setting-item" @tap="exportData">
					<text class="setting-name">导出数据</text>
					<text class="iconfont setting-arrow">></text>
				</view>
				<view class="setting-item" @tap="importData">
					<text class="setting-name">导入数据</text>
					<text class="iconfont setting-arrow">></text>
				</view>
				<view class="setting-item" @tap="shareScore">
					<text class="setting-name">分享成绩</text>
					<text class="iconfont setting-arrow">></text>
				</view>
				<view class="setting-item" @tap="refreshData">
					<text class="setting-name">刷新数据</text>
					<text class="iconfont setting-arrow">></text>
				</view>
				<view class="setting-item" @tap="clearData">
					<text class="setting-name">清除数据</text>
					<text class="iconfont setting-arrow">></text>
				</view>
				<view class="setting-item" @tap="about">
					<text class="setting-name">关于应用</text>
					<text class="iconfont setting-arrow">></text>
				</view>
			</view>
		</view>

		<!-- 意见反馈弹窗 -->
		<view v-if="showFeedback" class="feedback-modal" @tap="closeFeedbackModal">
			<view class="feedback-content" @tap.stop>
				<view class="feedback-header">
					<text class="feedback-title">💬 意见反馈</text>
					<text class="close-btn" @tap="closeFeedbackModal">✕</text>
				</view>
				
				<view class="feedback-form">
					<!-- 反馈类型选择 -->
					<view class="form-group">
						<text class="form-label">反馈类型</text>
						<view class="feedback-types">
							<view 
								v-for="type in feedbackTypes" 
								:key="type.value"
								class="type-item"
								:class="{ active: feedbackForm.type === type.value }"
								@tap="selectFeedbackType(type.value)"
							>
								<text class="type-icon">{{ type.icon }}</text>
								<text class="type-text">{{ type.label }}</text>
							</view>
						</view>
					</view>

					<!-- 反馈内容 -->
					<view class="form-group">
						<text class="form-label">详细描述</text>
						<textarea 
							class="feedback-textarea"
							v-model="feedbackForm.content"
							placeholder="请详细描述您遇到的问题或建议，我们会认真对待每一条反馈..."
							maxlength="500"
							:show-confirm-bar="false"
						></textarea>
						<text class="char-count">{{ feedbackForm.content.length }}/500</text>
					</view>

					<!-- 联系方式 -->
					<view class="form-group">
						<text class="form-label">联系方式（选填）</text>
						<input 
							class="feedback-input"
							v-model="feedbackForm.contact"
							placeholder="邮箱或微信号，便于我们回复您"
							maxlength="50"
						/>
					</view>

					<!-- 提交按钮 -->
					<view class="form-actions">
						<button 
							class="submit-btn"
							:class="{ disabled: !canSubmit }"
							:disabled="!canSubmit"
							@tap="submitFeedback"
						>
							{{ isSubmitting ? '提交中...' : '提交反馈' }}
						</button>
					</view>
				</view>
			</view>
		</view>

		<!-- 分享弹窗 -->
		<view v-if="showShareModal" class="share-modal" @tap="showShareModal = false">
			<view class="share-content" @tap.stop>
				<view class="share-header">
					<text class="share-title">📤 分享成绩</text>
					<text class="close-btn" @tap="showShareModal = false">✕</text>
				</view>
				
				<view class="share-options">
					<view class="share-option" @tap="generateShareCard">
						<view class="option-icon">🎨</view>
						<text class="option-text">生成成绩卡片</text>
						<text class="option-desc">制作精美的可视化成绩卡</text>
					</view>
					
					<view v-if="shareImagePath" class="share-option" @tap="saveShareImage">
						<view class="option-icon">💾</view>
						<text class="option-text">保存到相册</text>
						<text class="option-desc">保存成绩卡片到手机相册</text>
					</view>
					
					<view class="share-option" @tap="copyShareText">
						<view class="option-icon">📋</view>
						<text class="option-text">复制文本</text>
						<text class="option-desc">复制成绩文本到剪贴板</text>
					</view>
				</view>
				
				<!-- 预览区域 -->
				<view v-if="shareImagePath" class="share-preview">
					<text class="preview-title">预览</text>
					<image :src="shareImagePath" class="preview-image" mode="aspectFit"></image>
				</view>
			</view>
		</view>

		<!-- 隐藏的Canvas用于生成分享图片 -->
		<canvas canvas-id="shareCanvas" class="share-canvas"></canvas>
	</view>
</template>

<script setup>
import { ref, onMounted, computed } from 'vue'
import { isAuthenticated } from '@/utils/authManager.js'

// 分享相关状态
const showShareModal = ref(false)
const shareImagePath = ref('')

// 用户信息
const userInfo = ref({
	avatar: '/static/logo.png',
	nickname: '智力挑战者',
	id: '001234',
	joinDate: '2024-01-01'
})

// 综合智商分数
const overallIQ = ref(120)

// 智商等级
const iqLevel = computed(() => {
	const iq = overallIQ.value
	if (iq >= 140) return '天才级别'
	if (iq >= 130) return '极优秀'
	if (iq >= 120) return '优秀'
	if (iq >= 110) return '中上'
	if (iq >= 90) return '中等'
	if (iq >= 80) return '中下'
	return '待提升'
})

// 智商进度条
const iqProgress = computed(() => {
	return Math.min((overallIQ.value / 160) * 100, 100)
})

// 测试统计数据
const testStats = ref([
	{ name: '反应测试', icon: '⚡', count: 15, best: '245ms' },
	{ name: '记忆测试', icon: '🧠', count: 12, best: '8级' },
	{ name: '数字记忆', icon: '🔢', count: 20, best: '12位' },
	{ name: '语音记忆', icon: '🎵', count: 8, best: '7个词' },
	{ name: '黑猩猩测试', icon: '🐵', count: 10, best: '6级' },
	{ name: '视觉记忆', icon: '👁️', count: 14, best: '9个图形' },
	{ name: '打字测试', icon: '⌨️', count: 25, best: '85WPM' }
])

// 最近测试记录
const recentRecords = ref([
	{ testName: '反应时间测试', date: '2024-01-15', score: '245', unit: 'ms', icon: '⚡' },
	{ testName: '数字记忆', date: '2024-01-14', score: '12', unit: '位', icon: '🔢' },
	{ testName: '打字测试', date: '2024-01-13', score: '85', unit: 'WPM', icon: '⌨️' },
	{ testName: '视觉记忆', date: '2024-01-12', score: '9', unit: '个', icon: '👁️' }
])

// 成绩概览数据
const scoreOverview = ref([
	{ label: '总测试次数', value: '127次', icon: '📊', trend: 'up', trendText: '+12' },
	{ label: '平均得分', value: '85分', icon: '🎯', trend: 'up', trendText: '+3.2' },
	{ label: '最佳排名', value: '第15名', icon: '🏆', trend: 'up', trendText: '+5' },
	{ label: '连续天数', value: '7天', icon: '🔥', trend: 'stable', trendText: '持平' }
])

// 各项测试最佳成绩
const bestScores = ref([
	{ name: '反应测试', icon: '⚡', value: '245ms', progress: 85, level: '优秀' },
	{ name: '记忆测试', icon: '🧠', value: '8级', progress: 70, level: '良好' },
	{ name: '数字记忆', icon: '🔢', value: '12位', progress: 90, level: '优秀' },
	{ name: '语音记忆', icon: '🎵', value: '7个词', progress: 65, level: '良好' },
	{ name: '黑猩猩测试', icon: '🐵', value: '6级', progress: 75, level: '良好' },
	{ name: '视觉记忆', icon: '👁️', value: '9个图形', progress: 80, level: '优秀' },
	{ name: '打字测试', icon: '⌨️', value: '85WPM', progress: 88, level: '优秀' }
])

// 成就徽章
const achievements = ref([
	{ 
		id: 1,
		name: '初次尝试', 
		icon: '🏆', 
		description: '完成任意一个测试',
		condition: '完成1次测试',
		unlocked: false,
		progress: 0,
		maxProgress: 1,
		rarity: 'common',
		unlockDate: null
	},
	{ 
		id: 2,
		name: '反应达人', 
		icon: '⚡', 
		description: '反应时间低于250ms',
		condition: '反应时间 < 250ms',
		unlocked: false,
		progress: 0,
		maxProgress: 250,
		rarity: 'rare',
		unlockDate: null
	},
	{ 
		id: 3,
		name: '记忆大师', 
		icon: '🧠', 
		description: '数字记忆达到10位以上',
		condition: '数字记忆 ≥ 10位',
		unlocked: false,
		progress: 0,
		maxProgress: 10,
		rarity: 'epic',
		unlockDate: null
	},
	{ 
		id: 4,
		name: '速度之王', 
		icon: '🚀', 
		description: '打字速度达到80WPM以上',
		condition: '打字速度 ≥ 80WPM',
		unlocked: false,
		progress: 0,
		maxProgress: 80,
		rarity: 'rare',
		unlockDate: null
	},
	{ 
		id: 5,
		name: '完美主义', 
		icon: '💎', 
		description: '综合智商达到140以上',
		condition: '综合智商 ≥ 140',
		unlocked: false,
		progress: 0,
		maxProgress: 140,
		rarity: 'legendary',
		unlockDate: null
	},
	{ 
		id: 6,
		name: '坚持不懈', 
		icon: '🔥', 
		description: '总测试次数超过50次',
		condition: '完成50次测试',
		unlocked: false,
		progress: 0,
		maxProgress: 50,
		rarity: 'rare',
		unlockDate: null
	},
	{ 
		id: 7,
		name: '全能选手', 
		icon: '🌟', 
		description: '完成所有7种测试类型',
		condition: '完成全部测试类型',
		unlocked: false,
		progress: 0,
		maxProgress: 7,
		rarity: 'epic',
		unlockDate: null
	},
	{ 
		id: 8,
		name: '连击高手', 
		icon: '💥', 
		description: '连续7天进行测试',
		condition: '连续测试7天',
		unlocked: false,
		progress: 0,
		maxProgress: 7,
		rarity: 'rare',
		unlockDate: null
	},
	{ 
		id: 9,
		name: '视觉专家', 
		icon: '👁️', 
		description: '视觉记忆测试达到12个图形',
		condition: '视觉记忆 ≥ 12个',
		unlocked: false,
		progress: 0,
		maxProgress: 12,
		rarity: 'epic',
		unlockDate: null
	},
	{ 
		id: 10,
		name: '百发百中', 
		icon: '🎯', 
		description: '单次测试获得满分',
		condition: '获得满分成绩',
		unlocked: false,
		progress: 0,
		maxProgress: 1,
		rarity: 'legendary',
		unlockDate: null
	},
	{ 
		id: 11,
		name: '夜猫子', 
		icon: '🌙', 
		description: '在晚上11点后完成测试',
		condition: '深夜测试',
		unlocked: false,
		progress: 0,
		maxProgress: 1,
		rarity: 'common',
		unlockDate: null
	},
	{ 
		id: 12,
		name: '早起鸟儿', 
		icon: '🌅', 
		description: '在早上6点前完成测试',
		condition: '清晨测试',
		unlocked: false,
		progress: 0,
		maxProgress: 1,
		rarity: 'common',
		unlockDate: null
	},
	{ 
		id: 13,
		name: '签到新手', 
		icon: '📅', 
		description: '完成首次签到',
		condition: '签到1天',
		unlocked: false,
		progress: 0,
		maxProgress: 1,
		rarity: 'common',
		unlockDate: null
	},
	{ 
		id: 14,
		name: '签到达人', 
		icon: '🔥', 
		description: '连续签到7天',
		condition: '连续签到7天',
		unlocked: false,
		progress: 0,
		maxProgress: 7,
		rarity: 'rare',
		unlockDate: null
	},
	{ 
		id: 15,
		name: '签到专家', 
		icon: '💪', 
		description: '连续签到30天',
		condition: '连续签到30天',
		unlocked: false,
		progress: 0,
		maxProgress: 30,
		rarity: 'epic',
		unlockDate: null
	},
	{ 
		id: 16,
		name: '签到大师', 
		icon: '👑', 
		description: '连续签到100天',
		condition: '连续签到100天',
		unlocked: false,
		progress: 0,
		maxProgress: 100,
		rarity: 'legendary',
		unlockDate: null
	},
	{ 
		id: 17,
		name: '分享达人', 
		icon: '📤', 
		description: '分享成绩5次',
		condition: '分享5次成绩',
		unlocked: false,
		progress: 0,
		maxProgress: 5,
		rarity: 'rare',
		unlockDate: null
	},
	{ 
		id: 18,
		name: '进步之星', 
		icon: '📈', 
		description: '智商提升超过20分',
		condition: 'IQ提升≥20分',
		unlocked: false,
		progress: 0,
		maxProgress: 20,
		rarity: 'epic',
		unlockDate: null
	},
	{ 
		id: 19,
		name: '挑战者', 
		icon: '⚔️', 
		description: '单日完成10次测试',
		condition: '单日测试10次',
		unlocked: false,
		progress: 0,
		maxProgress: 10,
		rarity: 'rare',
		unlockDate: null
	},
	{ 
		id: 20,
		name: '收藏家', 
		icon: '🏆', 
		description: '解锁10个成就',
		condition: '解锁10个成就',
		unlocked: false,
		progress: 0,
		maxProgress: 10,
		rarity: 'epic',
		unlockDate: null
	}
])

// 成就详情弹窗显示状态
const showAchievementDetail = ref(false)
const selectedAchievement = ref(null)

// 最近解锁的成就
const recentUnlockedAchievements = ref([])

// 反馈功能相关状态
const showFeedback = ref(false)
const isSubmitting = ref(false)

// 反馈表单数据
const feedbackForm = ref({
	type: '',
	content: '',
	contact: ''
})

// 反馈类型选项
const feedbackTypes = ref([
	{ value: 'bug', label: '问题反馈', icon: '🐛' },
	{ value: 'suggestion', label: '功能建议', icon: '💡' },
	{ value: 'experience', label: '体验优化', icon: '✨' },
	{ value: 'other', label: '其他意见', icon: '💬' }
])

// 计算属性：是否可以提交
const canSubmit = computed(() => {
	return feedbackForm.value.type && 
		   feedbackForm.value.content.trim().length >= 10 && 
		   !isSubmitting.value
})

// 成就统计计算属性
const unlockedCount = computed(() => {
	return achievements.value.filter(a => a.unlocked).length
})

const legendaryCount = computed(() => {
	return achievements.value.filter(a => a.rarity === 'legendary' && a.unlocked).length
})

const epicCount = computed(() => {
	return achievements.value.filter(a => a.rarity === 'epic' && a.unlocked).length
})

const rareCount = computed(() => {
	return achievements.value.filter(a => a.rarity === 'rare' && a.unlocked).length
})

// 获取稀有度文本
const getRarityText = (rarity) => {
	const rarityMap = {
		common: '普通',
		rare: '稀有',
		epic: '史诗',
		legendary: '传奇'
	}
	return rarityMap[rarity] || '普通'
}

// 显示成就详情
const showBadgeDetail = (badge) => {
	selectedAchievement.value = badge
	showAchievementDetail.value = true
}

// 关闭成就详情弹窗
const closeAchievementDetail = () => {
	showAchievementDetail.value = false
	selectedAchievement.value = null
}

// 格式化日期
const formatDate = (dateString) => {
	if (!dateString) return '未知'
	const date = new Date(dateString)
	return date.toLocaleDateString('zh-CN', {
		year: 'numeric',
		month: '2-digit',
		day: '2-digit',
		hour: '2-digit',
		minute: '2-digit'
	})
}

// 解锁成就
const unlockAchievement = (achievementId) => {
	const achievement = achievements.value.find(a => a.id === achievementId)
	if (achievement && !achievement.unlocked) {
		achievement.unlocked = true
		achievement.unlockDate = new Date().toISOString()
		
		// 添加到最近解锁列表
		recentUnlockedAchievements.value.unshift(achievement)
		if (recentUnlockedAchievements.value.length > 5) {
			recentUnlockedAchievements.value.pop()
		}
		
		// 保存到本地存储
		uni.setStorageSync('achievements', achievements.value)
		uni.setStorageSync('recentUnlockedAchievements', recentUnlockedAchievements.value)
		
		// 显示解锁提示
		showUnlockNotification(achievement)
		
		return true
	}
	return false
}

// 显示解锁通知
const showUnlockNotification = (achievement) => {
	uni.showModal({
		title: '🎉 成就解锁！',
		content: `恭喜您解锁了「${achievement.name}」成就！\n\n${achievement.description}`,
		showCancel: false,
		confirmText: '太棒了！',
		confirmColor: '#007AFF'
	})
}

// 检查并更新成就进度
const checkAchievementProgress = (type, value) => {
	let hasNewUnlock = false
	
	achievements.value.forEach(achievement => {
		if (achievement.unlocked) return
		
		let shouldUpdate = false
		let newProgress = achievement.progress
		
		switch (achievement.id) {
			case 1: // 初次尝试
				if (type === 'test_completed') {
					newProgress = 1
					shouldUpdate = true
				}
				break
				
			case 2: // 反应达人
				if (type === 'reaction_time' && value < 250) {
					newProgress = Math.max(0, 250 - value)
					shouldUpdate = true
				}
				break
				
			case 3: // 记忆大师
				if (type === 'number_memory' && value >= 10) {
					newProgress = Math.min(value, achievement.maxProgress)
					shouldUpdate = true
				}
				break
				
			case 4: // 速度之王
				if (type === 'typing_speed' && value >= 80) {
					newProgress = Math.min(value, achievement.maxProgress)
					shouldUpdate = true
				}
				break
				
			case 5: // 完美主义
				if (type === 'overall_iq' && value >= 140) {
					newProgress = Math.min(value, achievement.maxProgress)
					shouldUpdate = true
				}
				break
				
			case 6: // 坚持不懈
				if (type === 'total_tests') {
					newProgress = Math.min(value, achievement.maxProgress)
					shouldUpdate = true
				}
				break
				
			case 7: // 全能选手
				if (type === 'test_types_completed') {
					newProgress = Math.min(value, achievement.maxProgress)
					shouldUpdate = true
				}
				break
				
			case 8: // 连击高手
				if (type === 'consecutive_days') {
					newProgress = Math.min(value, achievement.maxProgress)
					shouldUpdate = true
				}
				break
				
			case 9: // 视觉专家
				if (type === 'visual_memory' && value >= 12) {
					newProgress = Math.min(value, achievement.maxProgress)
					shouldUpdate = true
				}
				break
				
			case 10: // 百发百中
				if (type === 'perfect_score') {
					newProgress = 1
					shouldUpdate = true
				}
				break
				
			case 11: // 夜猫子
				if (type === 'night_test') {
					newProgress = 1
					shouldUpdate = true
				}
				break
				
			case 12: // 早起鸟儿
				if (type === 'early_test') {
					newProgress = 1
					shouldUpdate = true
				}
				break
		}
		
		if (shouldUpdate) {
			achievement.progress = newProgress
			
			// 检查是否达到解锁条件
			if (newProgress >= achievement.maxProgress) {
				if (unlockAchievement(achievement.id)) {
					hasNewUnlock = true
				}
			}
		}
	})
	
	// 保存进度
	uni.setStorageSync('achievements', achievements.value)
	
	return hasNewUnlock
}

// 页面加载时获取数据
onMounted(() => {
	// 检查登录状态，如果未登录则跳转到微信登录页面
	if (!isAuthenticated()) {
		uni.navigateTo({
			url: '/pages/wechat-login/wechat-login'
		})
		return
	}
	
	loadUserData()
	updateAchievements()
	calculateOverallIQ()
})

// 加载用户数据
const loadUserData = () => {
	// 从本地存储获取用户数据
	try {
		const savedUserInfo = uni.getStorageSync('userInfo')
		if (savedUserInfo) {
			userInfo.value = { ...userInfo.value, ...savedUserInfo }
		}
		
		const savedIQ = uni.getStorageSync('overallIQ')
		if (savedIQ) {
			overallIQ.value = savedIQ
		}
		
		// 从各个测试的历史数据中获取统计信息
		loadTestStatistics()
		loadRecentRecords()
		updateScoreOverview()
		updateBestScores()
	} catch (e) {
		console.error('加载用户数据失败:', e)
	}
}

// 加载测试统计数据
const loadTestStatistics = () => {
	try {
		// 反应测试统计
		const reactionHistory = uni.getStorageSync('reactionTestHistory')
		if (reactionHistory) {
			testStats.value[0].count = reactionHistory.testCount || 0
			testStats.value[0].best = reactionHistory.bestTime ? `${reactionHistory.bestTime}ms` : '未测试'
		}
		
		// 记忆测试统计
		const memoryHistory = uni.getStorageSync('memoryTestHistory')
		if (memoryHistory) {
			testStats.value[1].count = memoryHistory.testCount || 0
			testStats.value[1].best = memoryHistory.bestLevel ? `${memoryHistory.bestLevel}级` : '未测试'
		}
		
		// 数字记忆统计
		const numberHistory = uni.getStorageSync('numberMemoryHistory')
		if (numberHistory) {
			testStats.value[2].count = numberHistory.testCount || 0
			testStats.value[2].best = numberHistory.bestDigits ? `${numberHistory.bestDigits}位` : '未测试'
		}
		
		// 语音记忆统计
		const voiceHistory = uni.getStorageSync('voiceMemoryHistory')
		if (voiceHistory) {
			testStats.value[3].count = voiceHistory.testCount || 0
			testStats.value[3].best = voiceHistory.bestScore ? `${voiceHistory.bestScore}个词` : '未测试'
		}
		
		// 黑猩猩测试统计
		const chimpHistory = uni.getStorageSync('chimpTestHistory')
		if (chimpHistory) {
			testStats.value[4].count = chimpHistory.testCount || 0
			testStats.value[4].best = chimpHistory.bestLevel ? `${chimpHistory.bestLevel}级` : '未测试'
		}
		
		// 视觉记忆统计
		const visualHistory = uni.getStorageSync('visualMemoryHistory')
		if (visualHistory) {
			testStats.value[5].count = visualHistory.testCount || 0
			testStats.value[5].best = visualHistory.bestScore ? `${visualHistory.bestScore}个图形` : '未测试'
		}
		
		// 打字测试统计
		const typingHistory = uni.getStorageSync('typingTestHistory')
		if (typingHistory) {
			testStats.value[6].count = typingHistory.testCount || 0
			testStats.value[6].best = typingHistory.bestWPM ? `${typingHistory.bestWPM}WPM` : '未测试'
		}
	} catch (e) {
		console.error('加载测试统计失败:', e)
	}
}

// 加载最近记录
const loadRecentRecords = () => {
	try {
		const allRecords = []
		
		// 收集各个测试的最近记录
		const testTypes = [
			{ key: 'reactionTestHistory', name: '反应时间测试', icon: '⚡', unit: 'ms', scoreKey: 'bestTime' },
			{ key: 'numberMemoryHistory', name: '数字记忆', icon: '🔢', unit: '位', scoreKey: 'bestDigits' },
			{ key: 'typingTestHistory', name: '打字测试', icon: '⌨️', unit: 'WPM', scoreKey: 'bestWPM' },
			{ key: 'visualMemoryHistory', name: '视觉记忆', icon: '👁️', unit: '个', scoreKey: 'bestScore' }
		]
		
		testTypes.forEach(test => {
			const history = uni.getStorageSync(test.key)
			if (history && history.lastTest) {
				allRecords.push({
					testName: test.name,
					date: new Date(history.lastTest).toLocaleDateString(),
					score: history[test.scoreKey] || 0,
					unit: test.unit,
					icon: test.icon,
					timestamp: new Date(history.lastTest).getTime()
				})
			}
		})
		
		// 按时间排序，取最近4条
		allRecords.sort((a, b) => b.timestamp - a.timestamp)
		recentRecords.value = allRecords.slice(0, 4)
	} catch (e) {
		console.error('加载最近记录失败:', e)
	}
}

// 更新成绩概览
const updateScoreOverview = () => {
	try {
		let totalTests = 0
		let totalScore = 0
		let testCount = 0
		
		testStats.value.forEach(stat => {
			totalTests += stat.count
		})
		
		// 计算平均得分（这里简化处理）
		const histories = [
			uni.getStorageSync('reactionTestHistory'),
			uni.getStorageSync('memoryTestHistory'),
			uni.getStorageSync('numberMemoryHistory'),
			uni.getStorageSync('voiceMemoryHistory'),
			uni.getStorageSync('chimpTestHistory'),
			uni.getStorageSync('visualMemoryHistory'),
			uni.getStorageSync('typingTestHistory')
		]
		
		histories.forEach(history => {
			if (history && history.testCount) {
				testCount += history.testCount
				// 这里可以根据具体的评分标准计算
				totalScore += 80 // 简化处理
			}
		})
		
		const avgScore = testCount > 0 ? Math.round(totalScore / testCount) : 0
		
		scoreOverview.value[0].value = `${totalTests}次`
		scoreOverview.value[1].value = `${avgScore}分`
		
		// 计算连续天数
		const today = new Date().toDateString()
		const lastTestDate = recentRecords.value.length > 0 ? 
			new Date(recentRecords.value[0].timestamp).toDateString() : null
		
		if (lastTestDate === today) {
			scoreOverview.value[3].value = '今日已测试'
		} else {
			scoreOverview.value[3].value = '0天'
		}
	} catch (e) {
		console.error('更新成绩概览失败:', e)
	}
}

// 更新最佳成绩
const updateBestScores = () => {
	try {
		const testMappings = [
			{ index: 0, key: 'reactionTestHistory', scoreKey: 'bestTime', unit: 'ms', maxValue: 500 },
			{ index: 1, key: 'memoryTestHistory', scoreKey: 'bestLevel', unit: '级', maxValue: 10 },
			{ index: 2, key: 'numberMemoryHistory', scoreKey: 'bestDigits', unit: '位', maxValue: 15 },
			{ index: 3, key: 'voiceMemoryHistory', scoreKey: 'bestScore', unit: '个词', maxValue: 10 },
			{ index: 4, key: 'chimpTestHistory', scoreKey: 'bestLevel', unit: '级', maxValue: 8 },
			{ index: 5, key: 'visualMemoryHistory', scoreKey: 'bestScore', unit: '个图形', maxValue: 12 },
			{ index: 6, key: 'typingTestHistory', scoreKey: 'bestWPM', unit: 'WPM', maxValue: 100 }
		]
		
		testMappings.forEach(mapping => {
			const history = uni.getStorageSync(mapping.key)
			if (history && history[mapping.scoreKey]) {
				const score = history[mapping.scoreKey]
				let progress = 0
				let level = '待提升'
				
				// 计算进度条和等级
				if (mapping.index === 0) { // 反应测试，越小越好
					progress = Math.max(0, (mapping.maxValue - score) / mapping.maxValue * 100)
				} else {
					progress = Math.min(100, (score / mapping.maxValue) * 100)
				}
				
				if (progress >= 90) level = '优秀'
				else if (progress >= 70) level = '良好'
				else if (progress >= 50) level = '中等'
				
				bestScores.value[mapping.index].value = `${score}${mapping.unit}`
				bestScores.value[mapping.index].progress = Math.round(progress)
				bestScores.value[mapping.index].level = level
			}
		})
	} catch (e) {
		console.error('更新最佳成绩失败:', e)
	}
}

// 计算综合智商
const calculateOverallIQ = () => {
	try {
		let totalScore = 0
		let validTests = 0
		
		// 根据各项测试成绩计算综合IQ
		const testWeights = {
			reactionTestHistory: { weight: 0.15, scoreKey: 'bestTime', isReverse: true, baseScore: 300 },
			memoryTestHistory: { weight: 0.20, scoreKey: 'bestLevel', isReverse: false, baseScore: 5 },
			numberMemoryHistory: { weight: 0.20, scoreKey: 'bestDigits', isReverse: false, baseScore: 7 },
			voiceMemoryHistory: { weight: 0.15, scoreKey: 'bestScore', isReverse: false, baseScore: 4 },
			chimpTestHistory: { weight: 0.15, scoreKey: 'bestLevel', isReverse: false, baseScore: 3 },
			visualMemoryHistory: { weight: 0.10, scoreKey: 'bestScore', isReverse: false, baseScore: 6 },
			typingTestHistory: { weight: 0.05, scoreKey: 'bestWPM', isReverse: false, baseScore: 40 }
		}
		
		Object.keys(testWeights).forEach(key => {
			const history = uni.getStorageSync(key)
			const config = testWeights[key]
			
			if (history && history[config.scoreKey]) {
				let normalizedScore = 0
				const rawScore = history[config.scoreKey]
				
				if (config.isReverse) {
					// 反应时间等，越小越好
					normalizedScore = Math.max(0, (config.baseScore - rawScore) / config.baseScore)
				} else {
					// 其他测试，越大越好
					normalizedScore = Math.min(2, rawScore / config.baseScore)
				}
				
				totalScore += normalizedScore * config.weight * 100
				validTests += config.weight
			}
		})
		
		if (validTests > 0) {
			const calculatedIQ = Math.round(90 + (totalScore / validTests))
			overallIQ.value = Math.max(70, Math.min(160, calculatedIQ))
			
			// 保存计算结果
			uni.setStorageSync('overallIQ', overallIQ.value)
		}
	} catch (e) {
		console.error('计算综合智商失败:', e)
	}
}

// 更新成就徽章
const updateAchievements = () => {
	try {
		// 从本地存储加载成就数据
		const savedAchievements = uni.getStorageSync('achievements')
		if (savedAchievements && savedAchievements.length > 0) {
			// 合并保存的成就数据，保持现有结构但更新解锁状态和进度
			achievements.value.forEach((achievement, index) => {
				const saved = savedAchievements.find(a => a.id === achievement.id)
				if (saved) {
					achievement.unlocked = saved.unlocked
					achievement.progress = saved.progress || 0
					achievement.unlockDate = saved.unlockDate
				}
			})
		}
		
		// 加载最近解锁的成就
		const savedRecentUnlocked = uni.getStorageSync('recentUnlockedAchievements')
		if (savedRecentUnlocked) {
			recentUnlockedAchievements.value = savedRecentUnlocked
		}
		
		// 获取测试历史数据
		const reactionHistory = uni.getStorageSync('reactionHistory') || []
		let numberHistory = []
		try {
			const numberData = uni.getStorageSync('numberHistory')
			if (numberData) {
				numberHistory = typeof numberData === 'string' ? JSON.parse(numberData) : numberData
			}
		} catch (e) {
			console.error('解析数字记忆历史数据失败:', e)
			numberHistory = []
		}
		const visualHistory = uni.getStorageSync('visualHistory') || []
		const typingHistory = uni.getStorageSync('typingHistory') || []
		
		// 计算各种统计数据
		const totalTests = reactionHistory.length + numberHistory.length + visualHistory.length + typingHistory.length
		
		// 计算测试类型数量
		let testTypesCompleted = 0
		if (reactionHistory.length > 0) testTypesCompleted++
		if (numberHistory.length > 0) testTypesCompleted++
		if (visualHistory.length > 0) testTypesCompleted++
		if (typingHistory.length > 0) testTypesCompleted++
		
		// 计算连续测试天数
		const consecutiveDays = calculateConsecutiveDays([...reactionHistory, ...numberHistory, ...visualHistory, ...typingHistory])
		
		// 检查各种成就条件
		if (totalTests > 0) {
			checkAchievementProgress('test_completed', 1)
		}
		
		// 检查反应时间成就
		const bestReactionTime = reactionHistory.reduce((best, record) => {
			return record.averageTime < best ? record.averageTime : best
		}, Infinity)
		if (bestReactionTime < Infinity) {
			checkAchievementProgress('reaction_time', bestReactionTime)
		}
		
		// 检查数字记忆成就
		const bestNumberMemory = numberHistory.reduce((best, record) => {
			return record.score > best ? record.score : best
		}, 0)
		if (bestNumberMemory > 0) {
			checkAchievementProgress('number_memory', bestNumberMemory)
		}
		
		// 检查视觉记忆成就
		const bestVisualMemory = visualHistory.reduce((best, record) => {
			return record.score > best ? record.score : best
		}, 0)
		if (bestVisualMemory > 0) {
			checkAchievementProgress('visual_memory', bestVisualMemory)
		}
		
		// 检查打字速度成就
		const bestTypingSpeed = typingHistory.reduce((best, record) => {
			return record.wpm > best ? record.wpm : best
		}, 0)
		if (bestTypingSpeed > 0) {
			checkAchievementProgress('typing_speed', bestTypingSpeed)
		}
		
		// 检查完美主义成就（综合IQ）
		if (overallIQ.value > 0) {
			checkAchievementProgress('overall_iq', overallIQ.value)
		}
		
		// 检查坚持不懈成就
		if (totalTests > 0) {
			checkAchievementProgress('total_tests', totalTests)
		}
		
		// 检查全能选手成就
		if (testTypesCompleted > 0) {
			checkAchievementProgress('test_types_completed', testTypesCompleted)
		}
		
		// 检查连击高手成就
		if (consecutiveDays > 0) {
			checkAchievementProgress('consecutive_days', consecutiveDays)
		}
		
		// 检查完美分数成就
		const hasPerfectScore = [
			...reactionHistory.filter(r => r.averageTime < 200),
			...numberHistory.filter(r => r.score >= 15),
			...visualHistory.filter(r => r.score >= 16),
			...typingHistory.filter(r => r.accuracy >= 99)
		].length > 0
		if (hasPerfectScore) {
			checkAchievementProgress('perfect_score', 1)
		}
		
		// 检查时间相关成就
		const hasNightTest = [...reactionHistory, ...numberHistory, ...visualHistory, ...typingHistory]
			.some(record => {
				const hour = new Date(record.timestamp).getHours()
				return hour >= 22 || hour <= 6
			})
		if (hasNightTest) {
			checkAchievementProgress('night_test', 1)
		}
		
		const hasEarlyTest = [...reactionHistory, ...numberHistory, ...visualHistory, ...typingHistory]
			.some(record => {
				const hour = new Date(record.timestamp).getHours()
				return hour >= 5 && hour <= 8
			})
		if (hasEarlyTest) {
			checkAchievementProgress('early_test', 1)
		}
		
		// 检查触发器（从各个测试页面设置的触发器）
		checkTriggers()
	} catch (e) {
		console.error('更新成就徽章失败:', e)
	}
}

// 检查触发器
const checkTriggers = () => {
	try {
		// 检查反应时间触发器
		const reactionTrigger = uni.getStorageSync('achievementTrigger')
		if (reactionTrigger && reactionTrigger.type === 'reaction_time') {
			checkAchievementProgress('reaction_time', reactionTrigger.value)
			uni.removeStorageSync('achievementTrigger')
		}
		
		// 检查打字速度触发器
		const typingTrigger = uni.getStorageSync('typingSpeedTrigger')
		if (typingTrigger && typingTrigger.type === 'typing_speed') {
			checkAchievementProgress('typing_speed', typingTrigger.value)
			uni.removeStorageSync('typingSpeedTrigger')
		}
		
		// 检查数字记忆触发器
		const numberTrigger = uni.getStorageSync('numberMemoryTrigger')
		if (numberTrigger && numberTrigger.type === 'number_memory') {
			checkAchievementProgress('number_memory', numberTrigger.value)
			uni.removeStorageSync('numberMemoryTrigger')
		}
		
		// 检查视觉记忆触发器
		const visualTrigger = uni.getStorageSync('visualMemoryTrigger')
		if (visualTrigger && visualTrigger.type === 'visual_memory') {
			checkAchievementProgress('visual_memory', visualTrigger.value)
			uni.removeStorageSync('visualMemoryTrigger')
		}
		
		// 检查测试完成触发器
		const testCompleteTrigger = uni.getStorageSync('testCompleteTrigger')
		if (testCompleteTrigger && testCompleteTrigger.type === 'test_completed') {
			checkAchievementProgress('test_completed', testCompleteTrigger.value)
			uni.removeStorageSync('testCompleteTrigger')
		}
		
		// 检查完美分数触发器
		const perfectTrigger = uni.getStorageSync('perfectScoreTrigger')
		if (perfectTrigger && perfectTrigger.type === 'perfect_score') {
			checkAchievementProgress('perfect_score', perfectTrigger.value)
			uni.removeStorageSync('perfectScoreTrigger')
		}
		
		// 检查夜猫子触发器
		const nightTrigger = uni.getStorageSync('nightTestTrigger')
		if (nightTrigger && nightTrigger.type === 'night_test') {
			checkAchievementProgress('night_test', nightTrigger.value)
			uni.removeStorageSync('nightTestTrigger')
		}
		
		// 检查早起鸟儿触发器
		const earlyTrigger = uni.getStorageSync('earlyTestTrigger')
		if (earlyTrigger && earlyTrigger.type === 'early_test') {
			checkAchievementProgress('early_test', earlyTrigger.value)
			uni.removeStorageSync('earlyTestTrigger')
		}
	} catch (e) {
		console.error('检查触发器失败:', e)
	}
}

// 计算连续测试天数
const calculateConsecutiveDays = (allRecords) => {
	if (allRecords.length === 0) return 0
	
	// 按日期分组
	const dateGroups = {}
	allRecords.forEach(record => {
		const date = new Date(record.timestamp).toDateString()
		dateGroups[date] = true
	})
	
	// 获取所有测试日期并排序
	const testDates = Object.keys(dateGroups)
		.map(date => new Date(date))
		.sort((a, b) => b - a)
	
	if (testDates.length === 0) return 0
	
	// 计算连续天数
	let consecutiveDays = 1
	const today = new Date()
	today.setHours(0, 0, 0, 0)
	
	// 检查是否包含今天或昨天
	const latestTestDate = new Date(testDates[0])
	latestTestDate.setHours(0, 0, 0, 0)
	
	const daysDiff = Math.floor((today - latestTestDate) / (1000 * 60 * 60 * 24))
	if (daysDiff > 1) return 0 // 超过一天没测试，连续记录中断
	
	// 从最新日期开始计算连续天数
	for (let i = 1; i < testDates.length; i++) {
		const currentDate = new Date(testDates[i])
		const previousDate = new Date(testDates[i - 1])
		
		const diffDays = Math.floor((previousDate - currentDate) / (1000 * 60 * 60 * 24))
		
		if (diffDays === 1) {
			consecutiveDays++
		} else {
			break
		}
	}
	
	return consecutiveDays
}

// 选择头像
const chooseAvatar = () => {
	uni.chooseImage({
		count: 1,
		sizeType: ['compressed'],
		sourceType: ['album', 'camera'],
		success: (res) => {
			userInfo.value.avatar = res.tempFilePaths[0]
			saveUserInfo()
		}
	})
}

// 编辑个人资料
const editProfile = () => {
	uni.showModal({
		title: '编辑昵称',
		editable: true,
		placeholderText: userInfo.value.nickname,
		success: (res) => {
			if (res.confirm && res.content) {
				userInfo.value.nickname = res.content
				saveUserInfo()
			}
		}
	})
}

// 保存用户信息
const saveUserInfo = () => {
	try {
		uni.setStorageSync('userInfo', userInfo.value)
		uni.showToast({ title: '保存成功', icon: 'success' })
	} catch (e) {
		uni.showToast({ title: '保存失败', icon: 'error' })
	}
}

// 查看成绩分析
const viewScoreAnalysis = () => {
	uni.showModal({
		title: '成绩分析',
		content: '您的综合表现优秀，在反应速度和数字记忆方面表现突出，建议继续加强记忆训练。',
		showCancel: false
	})
}

// 查看所有记录
const viewAllRecords = () => {
	uni.navigateTo({
		url: '/pages/result/result'
	})
}

// 查看单个记录详情
const viewRecord = (record) => {
	uni.showModal({
		title: record.testName,
		content: `测试时间: ${record.date}\n测试成绩: ${record.score}${record.unit}`,
		showCancel: false
	})
}

// 导出数据
const exportData = () => {
	try {
		// 收集所有数据
		const exportData = {
			userInfo: userInfo.value,
			overallIQ: overallIQ.value,
			testHistory: {
				reactionTest: uni.getStorageSync('reactionTestHistory'),
				memoryTest: uni.getStorageSync('memoryTestHistory'),
				numberMemory: uni.getStorageSync('numberMemoryHistory'),
				voiceMemory: uni.getStorageSync('voiceMemoryHistory'),
				chimpTest: uni.getStorageSync('chimpTestHistory'),
				visualMemory: uni.getStorageSync('visualMemoryHistory'),
				typingTest: uni.getStorageSync('typingTestHistory')
			},
			exportTime: new Date().toISOString(),
			version: '1.0.0'
		}
		
		// 生成JSON字符串
		const jsonString = JSON.stringify(exportData, null, 2)
		
		// 在小程序中，我们可以将数据复制到剪贴板
		uni.setClipboardData({
			data: jsonString,
			success: () => {
				uni.showModal({
					title: '导出成功',
					content: '数据已复制到剪贴板，您可以粘贴到文件中保存',
					showCancel: false
				})
			},
			fail: () => {
				uni.showToast({
					title: '导出失败',
					icon: 'none'
				})
			}
		})
	} catch (e) {
		console.error('导出数据失败:', e)
		uni.showToast({
			title: '导出失败',
			icon: 'none'
		})
	}
}

// 清除数据
const clearData = () => {
	uni.showModal({
		title: '确认清除',
		content: '此操作将清除所有测试数据，无法恢复！请确认是否继续？',
		confirmText: '确认清除',
		confirmColor: '#ff4757',
		success: (res) => {
			if (res.confirm) {
				try {
					// 清除所有测试历史数据
					const keysToRemove = [
						'reactionTestHistory',
						'memoryTestHistory',
						'numberMemoryHistory',
						'voiceMemoryHistory',
						'chimpTestHistory',
						'visualMemoryHistory',
						'typingTestHistory',
						'overallIQ'
					]
					
					keysToRemove.forEach(key => {
						uni.removeStorageSync(key)
					})
					
					// 重置页面数据
					overallIQ.value = 100
					testStats.value.forEach(stat => {
						stat.count = 0
						stat.best = '未测试'
					})
					recentRecords.value = []
					scoreOverview.value.forEach(item => {
						if (item.label === '总测试次数') item.value = '0次'
						else if (item.label === '平均得分') item.value = '0分'
						else if (item.label === '连续天数') item.value = '0天'
					})
					bestScores.value.forEach(score => {
						score.value = '未测试'
						score.progress = 0
						score.level = '待提升'
					})
					achievements.value.forEach(achievement => {
						achievement.unlocked = false
					})
					
					uni.showToast({
						title: '数据已清除',
						icon: 'success'
					})
				} catch (e) {
					console.error('清除数据失败:', e)
					uni.showToast({
						title: '清除失败',
						icon: 'none'
					})
				}
			}
		}
	})
}

// 导入数据
const importData = () => {
	uni.showModal({
		title: '导入数据',
		content: '请先将导出的数据复制到剪贴板，然后点击确认导入',
		success: (res) => {
			if (res.confirm) {
				uni.getClipboardData({
					success: (clipRes) => {
						try {
							const importedData = JSON.parse(clipRes.data)
							
							// 验证数据格式
							if (!importedData.version || !importedData.testHistory) {
								throw new Error('数据格式不正确')
							}
							
							// 导入用户信息
							if (importedData.userInfo) {
								userInfo.value = { ...userInfo.value, ...importedData.userInfo }
								uni.setStorageSync('userInfo', userInfo.value)
							}
							
							// 导入测试历史
							Object.keys(importedData.testHistory).forEach(key => {
								const storageKey = key === 'reactionTest' ? 'reactionTestHistory' :
												  key === 'memoryTest' ? 'memoryTestHistory' :
												  key === 'numberMemory' ? 'numberMemoryHistory' :
												  key === 'voiceMemory' ? 'voiceMemoryHistory' :
												  key === 'chimpTest' ? 'chimpTestHistory' :
												  key === 'visualMemory' ? 'visualMemoryHistory' :
												  key === 'typingTest' ? 'typingTestHistory' : key
								
								if (importedData.testHistory[key]) {
									uni.setStorageSync(storageKey, importedData.testHistory[key])
								}
							})
							
							// 导入智商数据
							if (importedData.overallIQ) {
								overallIQ.value = importedData.overallIQ
								uni.setStorageSync('overallIQ', overallIQ.value)
							}
							
							// 重新加载数据
							loadUserData()
							updateAchievements()
							calculateOverallIQ()
							
							uni.showToast({
								title: '导入成功',
								icon: 'success'
							})
						} catch (e) {
							console.error('导入数据失败:', e)
							uni.showToast({
								title: '导入失败，请检查数据格式',
								icon: 'none'
							})
						}
					},
					fail: () => {
						uni.showToast({
							title: '获取剪贴板数据失败',
							icon: 'none'
						})
					}
				})
			}
		}
	})
}

// 关于应用
const about = () => {
	uni.showModal({
		title: '关于 BrainCube',
		content: 'BrainCube v1.0.0\n\n智能认知能力测试平台\n\n• 反应时间测试\n• 视觉记忆测试\n• 数字记忆测试\n• 打字速度测试\n• 综合智商评估\n\n开发者：AI Assistant\n技术栈：UniApp + Vue3',
		showCancel: false,
		confirmText: '了解'
	})
}

// 反馈功能方法
// 显示反馈弹窗
const showFeedbackModal = () => {
	showFeedback.value = true
}

// 关闭反馈弹窗
const closeFeedbackModal = () => {
	showFeedback.value = false
	// 重置表单
	feedbackForm.value = {
		type: '',
		content: '',
		contact: ''
	}
	isSubmitting.value = false
}

// 选择反馈类型
const selectFeedbackType = (type) => {
	feedbackForm.value.type = type
}

// 提交反馈
const submitFeedback = async () => {
	if (!canSubmit.value) return
	
	isSubmitting.value = true
	
	try {
		// 构建反馈数据
		const feedbackData = {
			id: Date.now().toString(),
			type: feedbackForm.value.type,
			content: feedbackForm.value.content.trim(),
			contact: feedbackForm.value.contact.trim(),
			userInfo: {
				nickname: userInfo.value.nickname,
				id: userInfo.value.id,
				overallIQ: overallIQ.value
			},
			deviceInfo: {
				platform: uni.getSystemInfoSync().platform,
				version: uni.getSystemInfoSync().version,
				model: uni.getSystemInfoSync().model
			},
			timestamp: new Date().toISOString(),
			status: 'pending'
		}
		
		// 保存到本地存储
		const existingFeedbacks = uni.getStorageSync('userFeedbacks') || []
		existingFeedbacks.unshift(feedbackData)
		
		// 只保留最近50条反馈记录
		if (existingFeedbacks.length > 50) {
			existingFeedbacks.splice(50)
		}
		
		uni.setStorageSync('userFeedbacks', existingFeedbacks)
		
		// 模拟网络请求延迟
		await new Promise(resolve => setTimeout(resolve, 1500))
		
		// 显示成功提示
		uni.showToast({
			title: '反馈提交成功！',
			icon: 'success',
			duration: 2000
		})
		
		// 关闭弹窗
		closeFeedbackModal()
		
	} catch (error) {
		console.error('提交反馈失败:', error)
		uni.showToast({
			title: '提交失败，请重试',
			icon: 'none',
			duration: 2000
		})
	} finally {
		isSubmitting.value = false
	}
}

// 分享成绩 - 优化版本，生成可视化成绩卡片
const shareScore = () => {
	showShareModal.value = true
}

// 生成分享卡片
const generateShareCard = () => {
	try {
		// 创建canvas绘制分享卡片
		const ctx = uni.createCanvasContext('shareCanvas')
		
		// 设置背景渐变
		const gradient = ctx.createLinearGradient(0, 0, 375, 500)
		gradient.addColorStop(0, '#667eea')
		gradient.addColorStop(1, '#764ba2')
		ctx.setFillStyle(gradient)
		ctx.fillRect(0, 0, 375, 500)
		
		// 绘制用户信息
		ctx.setFillStyle('#ffffff')
		ctx.setFontSize(24)
		ctx.setTextAlign('center')
		ctx.fillText(userInfo.value.nickname, 187.5, 80)
		
		// 绘制智商分数
		ctx.setFontSize(48)
		ctx.fillText(`智商: ${overallIQ.value}`, 187.5, 150)
		
		// 绘制等级
		ctx.setFontSize(18)
		ctx.fillText(iqLevel.value, 187.5, 180)
		
		// 绘制测试统计
		ctx.setFontSize(16)
		ctx.setTextAlign('left')
		const totalTests = testStats.value.reduce((sum, stat) => sum + stat.count, 0)
		ctx.fillText(`总测试次数: ${totalTests}次`, 30, 220)
		
		// 绘制最佳成绩（前3项）
		let yPos = 260
		bestScores.value.slice(0, 3).forEach((score, index) => {
			ctx.fillText(`${score.name}: ${score.value}`, 30, yPos)
			yPos += 30
		})
		
		// 绘制底部文字
		ctx.setTextAlign('center')
		ctx.setFontSize(14)
		ctx.fillText('来BrainCube挑战你的认知极限！', 187.5, 420)
		
		ctx.draw(false, () => {
			// 生成图片
			uni.canvasToTempFilePath({
				canvasId: 'shareCanvas',
				success: (res) => {
					shareImagePath.value = res.tempFilePath
					uni.showToast({
						title: '成绩卡片已生成',
						icon: 'success'
					})
				},
				fail: (err) => {
					console.error('生成分享图片失败:', err)
					uni.showToast({
						title: '生成失败',
						icon: 'none'
					})
				}
			})
		})
	} catch (e) {
		console.error('生成分享卡片失败:', e)
		uni.showToast({
			title: '生成失败',
			icon: 'none'
		})
	}
}

// 保存分享图片
const saveShareImage = () => {
	if (!shareImagePath.value) {
		uni.showToast({
			title: '请先生成分享卡片',
			icon: 'none'
		})
		return
	}
	
	uni.saveImageToPhotosAlbum({
		filePath: shareImagePath.value,
		success: () => {
			uni.showToast({
				title: '已保存到相册',
				icon: 'success'
			})
			showShareModal.value = false
		},
		fail: (err) => {
			console.error('保存图片失败:', err)
			uni.showToast({
				title: '保存失败',
				icon: 'none'
			})
		}
	})
}

// 复制文本分享
const copyShareText = () => {
	const shareText = `我在 BrainCube 上的测试成绩：\n\n🧠 综合智商：${overallIQ.value}\n📊 总测试次数：${testStats.value.reduce((sum, stat) => sum + stat.count, 0)}次\n\n各项最佳成绩：\n${bestScores.value.map(score => `${score.name}：${score.value}`).join('\n')}\n\n快来挑战你的认知极限吧！`
	
	uni.setClipboardData({
		data: shareText,
		success: () => {
			uni.showToast({
				title: '成绩已复制到剪贴板',
				icon: 'success'
			})
			showShareModal.value = false
		}
	})
}

// 刷新数据
const refreshData = () => {
	uni.showLoading({
		title: '刷新中...'
	})
	
	setTimeout(() => {
		loadUserData()
		updateAchievements()
		calculateOverallIQ()
		
		uni.hideLoading()
		uni.showToast({
			title: '刷新完成',
			icon: 'success'
		})
	}, 1000)
}
</script>

<style lang="scss" scoped>
.profile-container {
	padding: 20rpx;
	background-color: #f5f5f5;
	min-height: 100vh;
}

// 用户信息卡片
.user-card {
	background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
	border-radius: 20rpx;
	padding: 40rpx;
	margin-bottom: 20rpx;
	display: flex;
	align-items: center;
	position: relative;

	.user-avatar {
		width: 120rpx;
		height: 120rpx;
		border-radius: 60rpx;
		overflow: hidden;
		border: 4rpx solid rgba(255, 255, 255, 0.3);
		margin-right: 30rpx;

		image {
			width: 100%;
			height: 100%;
		}
	}

	.user-info {
		flex: 1;

		.username {
			font-size: 36rpx;
			font-weight: bold;
			color: white;
			display: block;
			margin-bottom: 10rpx;
		}

		.user-id, .join-date {
			font-size: 24rpx;
			color: rgba(255, 255, 255, 0.8);
			display: block;
			margin-bottom: 5rpx;
		}
	}

	.edit-btn {
		background: rgba(255, 255, 255, 0.2);
		border-radius: 30rpx;
		padding: 15rpx 30rpx;
		border: 2rpx solid rgba(255, 255, 255, 0.3);

		text {
			color: white;
			font-size: 28rpx;
		}
	}
}

// 智商评估卡片
.iq-card {
	background: white;
	border-radius: 20rpx;
	padding: 30rpx;
	margin-bottom: 20rpx;
	box-shadow: 0 4rpx 20rpx rgba(0, 0, 0, 0.1);

	.iq-header {
		display: flex;
		justify-content: space-between;
		align-items: center;
		margin-bottom: 20rpx;

		.iq-title {
			font-size: 32rpx;
			font-weight: bold;
			color: #333;
		}

		.iq-score {
			font-size: 48rpx;
			font-weight: bold;
			color: #007AFF;
		}
	}

	.iq-level {
		.level-text {
			font-size: 28rpx;
			color: #666;
			display: block;
			margin-bottom: 15rpx;
		}

		.level-bar {
			height: 12rpx;
			background: #f0f0f0;
			border-radius: 6rpx;
			overflow: hidden;

			.level-progress {
				height: 100%;
				background: linear-gradient(90deg, #007AFF, #00D4FF);
				transition: width 0.3s ease;
			}
		}
	}
}

// 通用section样式
.stats-section, .scores-section, .recent-section, .achievement-section, .settings-section {
	background: white;
	border-radius: 20rpx;
	padding: 30rpx;
	margin-bottom: 20rpx;
	box-shadow: 0 4rpx 20rpx rgba(0, 0, 0, 0.1);
}

.section-title {
	font-size: 32rpx;
	font-weight: bold;
	color: #333;
	margin-bottom: 25rpx;
	display: block;
}

.section-header {
	display: flex;
	justify-content: space-between;
	align-items: center;
	margin-bottom: 25rpx;

	.view-all {
		font-size: 28rpx;
		color: #007AFF;
	}
}

// 测试统计网格
.stats-grid {
	display: grid;
	grid-template-columns: repeat(2, 1fr);
	gap: 20rpx;

	.stat-item {
		display: flex;
		align-items: center;
		padding: 20rpx;
		background: #f8f9fa;
		border-radius: 15rpx;

		.stat-icon {
			width: 60rpx;
			height: 60rpx;
			border-radius: 30rpx;
			background: #007AFF;
			display: flex;
			align-items: center;
			justify-content: center;
			margin-right: 15rpx;

			text {
				font-size: 24rpx;
			}
		}

		.stat-info {
			flex: 1;

			.stat-name {
				font-size: 26rpx;
				color: #333;
				display: block;
				margin-bottom: 5rpx;
			}

			.stat-count, .stat-best {
				font-size: 22rpx;
				color: #666;
				display: block;
			}
		}
	}
}

// 最近记录列表
.record-list {
	.record-item {
		display: flex;
		align-items: center;
		padding: 25rpx 0;
		border-bottom: 1rpx solid #f0f0f0;

		&:last-child {
			border-bottom: none;
		}

		.record-icon {
			width: 60rpx;
			height: 60rpx;
			border-radius: 30rpx;
			background: #f8f9fa;
			display: flex;
			align-items: center;
			justify-content: center;
			margin-right: 20rpx;

			text {
				font-size: 24rpx;
			}
		}

		.record-info {
			flex: 1;

			.record-name {
				font-size: 30rpx;
				color: #333;
				display: block;
				margin-bottom: 8rpx;
			}

			.record-date {
				font-size: 24rpx;
				color: #999;
				display: block;
			}
		}

		.record-score {
			text-align: right;

			.score-value {
				font-size: 32rpx;
				font-weight: bold;
				color: #007AFF;
				display: block;
			}

			.score-unit {
				font-size: 22rpx;
				color: #666;
				display: block;
			}
		}
	}
}

// 成就徽章网格
.badge-grid {
	display: grid;
	grid-template-columns: repeat(3, 1fr);
	gap: 20rpx;

	.badge-item {
		display: flex;
		flex-direction: column;
		align-items: center;
		padding: 25rpx;
		border-radius: 15rpx;
		background: #f8f9fa;
		transition: all 0.3s ease;
		position: relative;
		border: 2rpx solid transparent;

		&.unlocked {
			color: white;
			transform: scale(1.02);
			
			&.common {
				background: linear-gradient(135deg, #74b9ff 0%, #0984e3 100%);
				border-color: #74b9ff;
				box-shadow: 0 6rpx 20rpx rgba(116, 185, 255, 0.3);
			}
			
			&.rare {
				background: linear-gradient(135deg, #00b894 0%, #00a085 100%);
				border-color: #00b894;
				box-shadow: 0 6rpx 20rpx rgba(0, 184, 148, 0.3);
			}
			
			&.epic {
				background: linear-gradient(135deg, #a29bfe 0%, #6c5ce7 100%);
				border-color: #a29bfe;
				box-shadow: 0 6rpx 20rpx rgba(162, 155, 254, 0.3);
			}
			
			&.legendary {
				background: linear-gradient(135deg, #fdcb6e 0%, #e17055 100%);
				border-color: #fdcb6e;
				box-shadow: 0 8rpx 25rpx rgba(253, 203, 110, 0.4);
				animation: legendary-glow 2s ease-in-out infinite alternate;
			}
		}

		&.has-progress {
			opacity: 0.8;
			border-color: #007AFF;
		}

		.badge-icon {
			width: 60rpx;
			height: 60rpx;
			border-radius: 30rpx;
			background: rgba(255, 255, 255, 0.3);
			display: flex;
			align-items: center;
			justify-content: center;
			margin-bottom: 10rpx;
			position: relative;

			text {
				font-size: 24rpx;
			}

			.unlock-effect {
				position: absolute;
				top: -5rpx;
				right: -5rpx;
				width: 20rpx;
				height: 20rpx;
				background: #FFD700;
				border-radius: 50%;
				animation: unlock-pulse 1.5s ease-in-out infinite;
			}
		}

		.badge-name {
			font-size: 22rpx;
			color: #333;
			text-align: center;
			margin-bottom: 8rpx;
		}

		.badge-progress {
			width: 100%;
			margin-bottom: 8rpx;

			.progress-bar {
				height: 6rpx;
				background: rgba(0, 0, 0, 0.1);
				border-radius: 3rpx;
				overflow: hidden;

				.progress-fill {
					height: 100%;
					background: linear-gradient(90deg, #007AFF, #00D4FF);
					transition: width 0.5s ease;
				}
			}

			.progress-text {
				font-size: 18rpx;
				color: #666;
				text-align: center;
				margin-top: 4rpx;
				display: block;
			}
		}

		.rarity-badge {
			position: absolute;
			top: 8rpx;
			right: 8rpx;
			padding: 2rpx 8rpx;
			border-radius: 10rpx;
			font-size: 16rpx;
			font-weight: bold;
			text-transform: uppercase;
			letter-spacing: 1rpx;

			&.common {
				background: rgba(116, 185, 255, 0.2);
				color: #74b9ff;
			}

			&.rare {
				background: rgba(0, 184, 148, 0.2);
				color: #00b894;
			}

			&.epic {
				background: rgba(162, 155, 254, 0.2);
				color: #a29bfe;
			}

			&.legendary {
				background: rgba(253, 203, 110, 0.2);
				color: #fdcb6e;
			}
		}
	}
}

@keyframes legendary-glow {
	0% {
		box-shadow: 0 8rpx 25rpx rgba(253, 203, 110, 0.4);
	}
	100% {
		box-shadow: 0 12rpx 35rpx rgba(253, 203, 110, 0.6), 0 0 20rpx rgba(253, 203, 110, 0.3);
	}
}

@keyframes unlock-pulse {
	0%, 100% {
		transform: scale(1);
		opacity: 1;
	}
	50% {
		transform: scale(1.2);
		opacity: 0.7;
	}
}

// 成就统计样式
.achievement-stats {
	display: flex;
	justify-content: space-around;
	margin-bottom: 25rpx;
	padding: 20rpx;
	background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
	border-radius: 15rpx;
	color: white;

	.stat-item {
		text-align: center;

		.stat-label {
			font-size: 20rpx;
			opacity: 0.9;
			font-weight: 500;
			display: block;
			margin-bottom: 5rpx;
		}

		.stat-value {
			font-size: 32rpx;
			font-weight: 700;
			display: block;

			&.legendary {
				color: #fdcb6e;
				text-shadow: 0 0 10rpx rgba(253, 203, 110, 0.5);
			}

			&.epic {
				color: #a29bfe;
			}

			&.rare {
				color: #00b894;
			}
		}
	}
}

// 成就详情弹窗
.achievement-modal {
	position: fixed;
	top: 0;
	left: 0;
	right: 0;
	bottom: 0;
	background: rgba(0, 0, 0, 0.5);
	display: flex;
	align-items: center;
	justify-content: center;
	z-index: 1000;
	padding: 40rpx;

	.modal-content {
		background: white;
		border-radius: 20rpx;
		padding: 40rpx;
		max-width: 600rpx;
		width: 100%;
		max-height: 80vh;
		overflow-y: auto;
		position: relative;
		animation: modal-appear 0.3s ease-out;

		.modal-header {
			display: flex;
			align-items: center;
			margin-bottom: 30rpx;
			position: relative;

			.achievement-icon {
				width: 80rpx;
				height: 80rpx;
				border-radius: 40rpx;
				display: flex;
				align-items: center;
				justify-content: center;
				margin-right: 20rpx;
				font-size: 36rpx;
				background: #f8f9fa;

				&.unlocked {
					&.common {
						background: linear-gradient(135deg, #74b9ff 0%, #0984e3 100%);
						color: white;
					}

					&.rare {
						background: linear-gradient(135deg, #00b894 0%, #00a085 100%);
						color: white;
					}

					&.epic {
						background: linear-gradient(135deg, #a29bfe 0%, #6c5ce7 100%);
						color: white;
					}

					&.legendary {
						background: linear-gradient(135deg, #fdcb6e 0%, #e17055 100%);
						color: white;
					}
				}
			}

			.achievement-info {
				flex: 1;

				.achievement-title {
					font-size: 32rpx;
					font-weight: 600;
					color: #333;
					display: block;
					margin-bottom: 8rpx;
				}

				.achievement-rarity {
					display: inline-block;
					padding: 4rpx 12rpx;
					border-radius: 20rpx;
					font-size: 20rpx;
					font-weight: 600;
					text-transform: uppercase;
					letter-spacing: 1rpx;

					&.common {
						background: #74b9ff;
						color: white;
					}

					&.rare {
						background: #00b894;
						color: white;
					}

					&.epic {
						background: #a29bfe;
						color: white;
					}

					&.legendary {
						background: linear-gradient(135deg, #fdcb6e 0%, #e17055 100%);
						color: white;
					}
				}
			}

			.close-btn {
				position: absolute;
				top: -10rpx;
				right: -10rpx;
				width: 60rpx;
				height: 60rpx;
				border-radius: 30rpx;
				background: #f0f0f0;
				display: flex;
				align-items: center;
				justify-content: center;
				font-size: 36rpx;
				color: #666;
				transition: all 0.2s ease;

				&:active {
					background: #e0e0e0;
					color: #333;
				}
			}
		}

		.modal-body {
			.achievement-description {
				color: #666;
				line-height: 1.6;
				margin-bottom: 25rpx;
				font-size: 28rpx;
				display: block;
			}

			.achievement-condition {
				background: #f8f9fa;
				padding: 20rpx;
				border-radius: 12rpx;
				margin-bottom: 25rpx;
				font-size: 26rpx;
				color: #333;
				font-weight: 500;
				display: block;
			}

			.progress-section {
				margin-bottom: 25rpx;

				.progress-header {
					display: flex;
					justify-content: space-between;
					align-items: center;
					margin-bottom: 15rpx;

					.progress-label {
						font-size: 24rpx;
						color: #888;
						font-weight: 500;
						display: block;
					}

					.progress-value {
						font-size: 28rpx;
						color: #333;
						font-weight: 600;
						display: block;
					}
				}

				.progress-bar-large {
					height: 12rpx;
					background: #e9ecef;
					border-radius: 6rpx;
					overflow: hidden;
					margin-bottom: 10rpx;

					.progress-fill {
						height: 100%;
						background: linear-gradient(90deg, #74b9ff 0%, #0984e3 100%);
						transition: width 0.5s ease;
						border-radius: 6rpx;
					}
				}

				.progress-percent {
					text-align: center;
					font-size: 24rpx;
					color: #666;
					font-weight: 500;
					display: block;
				}
			}

			.unlock-info {
				text-align: center;
				padding: 20rpx;
				background: #e8f5e8;
				border-radius: 12rpx;

				.unlock-status {
					font-size: 28rpx;
					color: #2d5a2d;
					font-weight: 600;
					display: block;
					margin-bottom: 8rpx;
				}

				.unlock-date {
					font-size: 24rpx;
					color: #2d5a2d;
					display: block;
				}
			}
		}
	}
}

@keyframes modal-appear {
	0% {
		opacity: 0;
		transform: scale(0.9) translateY(-40rpx);
	}
	100% {
		opacity: 1;
		transform: scale(1) translateY(0);
	}
}

// 成绩概览样式
.score-overview {
	display: grid;
	grid-template-columns: repeat(2, 1fr);
	gap: 15rpx;
	margin-bottom: 30rpx;

	.overview-item {
		display: flex;
		align-items: center;
		padding: 20rpx;
		background: #f8f9fa;
		border-radius: 15rpx;
		position: relative;

		.overview-icon {
			font-size: 32rpx;
			margin-right: 15rpx;
		}

		.overview-info {
			flex: 1;

			.overview-label {
				font-size: 22rpx;
				color: #666;
				display: block;
				margin-bottom: 5rpx;
			}

			.overview-value {
				font-size: 28rpx;
				font-weight: bold;
				color: #333;
				display: block;
			}
		}

		.overview-trend {
			position: absolute;
			top: 10rpx;
			right: 10rpx;
			font-size: 18rpx;
			padding: 4rpx 8rpx;
			border-radius: 8rpx;

			&.up {
				background: #e8f5e8;
				color: #52c41a;
			}

			&.down {
				background: #fff2f0;
				color: #ff4d4f;
			}

			&.stable {
				background: #f0f0f0;
				color: #999;
			}
		}
	}
}

// 最佳成绩样式
.best-scores {
	.best-score-item {
		margin-bottom: 20rpx;
		padding: 20rpx;
		background: #f8f9fa;
		border-radius: 15rpx;

		&:last-child {
			margin-bottom: 0;
		}

		.score-header {
			display: flex;
			align-items: center;
			margin-bottom: 15rpx;

			.score-icon {
				font-size: 28rpx;
				margin-right: 15rpx;
			}

			.score-name {
				flex: 1;
				font-size: 26rpx;
				color: #333;
			}

			.score-value {
				font-size: 28rpx;
				font-weight: bold;
				color: #007AFF;
			}
		}

		.score-progress {
			display: flex;
			align-items: center;
			gap: 15rpx;

			.progress-bar {
				flex: 1;
				height: 8rpx;
				background: #e0e0e0;
				border-radius: 4rpx;
				overflow: hidden;

				.progress-fill {
					height: 100%;
					background: linear-gradient(90deg, #007AFF, #00D4FF);
					transition: width 0.3s ease;
				}
			}

			.progress-text {
				font-size: 22rpx;
				color: #666;
			}
		}
	}
}

// 设置列表
.setting-list {
	.setting-item {
		display: flex;
		align-items: center;
		justify-content: space-between;
		padding: 30rpx 0;
		border-bottom: 1rpx solid #f0f0f0;

		&:last-child {
			border-bottom: none;
		}

		.setting-name {
			font-size: 30rpx;
			color: #333;
		}

		.setting-arrow {
			font-size: 24rpx;
			color: #ccc;
		}
	}
}

// 反馈弹窗样式
.feedback-modal {
	position: fixed;
	top: 0;
	left: 0;
	right: 0;
	bottom: 0;
	background: rgba(0, 0, 0, 0.5);
	display: flex;
	align-items: center;
	justify-content: center;
	z-index: 1000;
	padding: 40rpx;

	.feedback-content {
		background: white;
		border-radius: 20rpx;
		padding: 0;
		max-width: 600rpx;
		width: 100%;
		max-height: 80vh;
		overflow: hidden;
		animation: modal-appear 0.3s ease-out;

		.feedback-header {
			display: flex;
			align-items: center;
			justify-content: space-between;
			padding: 30rpx 40rpx;
			border-bottom: 1rpx solid #f0f0f0;
			background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
			border-radius: 20rpx 20rpx 0 0;

			.feedback-title {
				font-size: 32rpx;
				font-weight: bold;
				color: white;
			}

			.close-btn {
				font-size: 32rpx;
				color: rgba(255, 255, 255, 0.8);
				padding: 10rpx;
				border-radius: 50%;
				transition: all 0.3s ease;

				&:active {
					background: rgba(255, 255, 255, 0.1);
					transform: scale(0.9);
				}
			}
		}

		.feedback-form {
			padding: 40rpx;
			max-height: calc(80vh - 120rpx);
			overflow-y: auto;

			.form-group {
				margin-bottom: 30rpx;

				.form-label {
					font-size: 28rpx;
					color: #333;
					font-weight: 600;
					display: block;
					margin-bottom: 15rpx;
				}

				.feedback-types {
					display: grid;
					grid-template-columns: repeat(2, 1fr);
					gap: 15rpx;

					.type-item {
						display: flex;
						flex-direction: column;
						align-items: center;
						padding: 20rpx;
						border: 2rpx solid #e0e0e0;
						border-radius: 15rpx;
						background: #f8f9fa;
						transition: all 0.3s ease;
						cursor: pointer;

						&.active {
							border-color: #007AFF;
							background: linear-gradient(135deg, #007AFF, #00D4FF);
							color: white;
							transform: translateY(-2rpx);
							box-shadow: 0 8rpx 25rpx rgba(0, 122, 255, 0.3);

							.type-text {
								color: white;
							}
						}

						&:active {
							transform: scale(0.95);
						}

						.type-icon {
							font-size: 32rpx;
							margin-bottom: 8rpx;
						}

						.type-text {
							font-size: 24rpx;
							color: #666;
							font-weight: 500;
						}
					}
				}

				.feedback-textarea {
					width: 100%;
					min-height: 200rpx;
					padding: 20rpx;
					border: 2rpx solid #e0e0e0;
					border-radius: 15rpx;
					background: #f8f9fa;
					font-size: 28rpx;
					color: #333;
					line-height: 1.5;
					resize: none;
					transition: all 0.3s ease;

					&:focus {
						border-color: #007AFF;
						background: white;
						box-shadow: 0 0 0 4rpx rgba(0, 122, 255, 0.1);
					}
				}

				.char-count {
					font-size: 22rpx;
					color: #999;
					text-align: right;
					margin-top: 8rpx;
					display: block;
				}

				.feedback-input {
					width: 100%;
					padding: 20rpx;
					border: 2rpx solid #e0e0e0;
					border-radius: 15rpx;
					background: #f8f9fa;
					font-size: 28rpx;
					color: #333;
					transition: all 0.3s ease;

					&:focus {
						border-color: #007AFF;
						background: white;
						box-shadow: 0 0 0 4rpx rgba(0, 122, 255, 0.1);
					}
				}
			}

			.form-actions {
				margin-top: 40rpx;

				.submit-btn {
					width: 100%;
					padding: 25rpx;
					border-radius: 15rpx;
					background: linear-gradient(135deg, #007AFF, #00D4FF);
					color: white;
					font-size: 30rpx;
					font-weight: 600;
					border: none;
					transition: all 0.3s ease;
					box-shadow: 0 8rpx 25rpx rgba(0, 122, 255, 0.3);

					&:active {
						transform: translateY(2rpx);
						box-shadow: 0 4rpx 15rpx rgba(0, 122, 255, 0.2);
					}

					&.disabled {
						background: #ccc;
						box-shadow: none;
						cursor: not-allowed;
						opacity: 0.6;

						&:active {
							transform: none;
						}
					}
				}
			}
		}
	}
}

@keyframes modal-appear {
	0% {
		opacity: 0;
		transform: scale(0.9) translateY(-40rpx);
	}
	100% {
		opacity: 1;
		transform: scale(1) translateY(0);
	}
}

// 分享弹窗样式
.share-modal {
	position: fixed;
	top: 0;
	left: 0;
	right: 0;
	bottom: 0;
	background: rgba(0, 0, 0, 0.5);
	display: flex;
	align-items: center;
	justify-content: center;
	z-index: 1000;
	padding: 40rpx;

	.share-content {
		background: white;
		border-radius: 20rpx;
		padding: 0;
		max-width: 600rpx;
		width: 100%;
		max-height: 80vh;
		overflow: hidden;
		animation: modal-appear 0.3s ease-out;

		.share-header {
			display: flex;
			align-items: center;
			justify-content: space-between;
			padding: 30rpx 40rpx;
			border-bottom: 1rpx solid #f0f0f0;
			background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
			border-radius: 20rpx 20rpx 0 0;

			.share-title {
				font-size: 32rpx;
				font-weight: bold;
				color: white;
			}

			.close-btn {
				font-size: 32rpx;
				color: rgba(255, 255, 255, 0.8);
				padding: 10rpx;
				border-radius: 50%;
				transition: all 0.3s ease;

				&:active {
					background: rgba(255, 255, 255, 0.1);
					transform: scale(0.9);
				}
			}
		}

		.share-options {
			padding: 30rpx;

			.share-option {
				display: flex;
				align-items: center;
				padding: 25rpx;
				margin-bottom: 20rpx;
				border: 2rpx solid #f0f0f0;
				border-radius: 15rpx;
				background: #f8f9fa;
				transition: all 0.3s ease;
				cursor: pointer;

				&:last-child {
					margin-bottom: 0;
				}

				&:active {
					background: #e9ecef;
					transform: scale(0.98);
				}

				.option-icon {
					font-size: 40rpx;
					margin-right: 20rpx;
					width: 60rpx;
					text-align: center;
				}

				.option-text {
					font-size: 30rpx;
					font-weight: 600;
					color: #333;
					display: block;
					margin-bottom: 5rpx;
				}

				.option-desc {
					font-size: 24rpx;
					color: #666;
					display: block;
				}
			}
		}

		.share-preview {
			padding: 0 30rpx 30rpx;

			.preview-title {
				font-size: 28rpx;
				font-weight: 600;
				color: #333;
				display: block;
				margin-bottom: 15rpx;
			}

			.preview-image {
				width: 100%;
				height: 300rpx;
				border-radius: 10rpx;
				border: 1rpx solid #e0e0e0;
			}
		}
	}
}

// 隐藏的Canvas
.share-canvas {
	position: fixed;
	top: -9999rpx;
	left: -9999rpx;
	width: 375px;
	height: 500px;
}
</style>
